#ifndef _HAAR_LIKE_DETECTOR_H_
#define _HAAR_LIKE_DETECTOR_H_

#include "Detector.h"

#define USE_GENERAL_CONFIDANCE

using namespace std;

class HaarLikeDetector : public Detector
{
public:

	HaarLikeDetector(std::string inClassifierPath, 
		std::string inObjectType = "NO CLASSIFIER",
		double inAPrioriConfidence = 1.0,
		double inScaleFactor = 1.1, 
		int inMinNeighbors = 3, 
		int inFlags = 0, 
		cv::Size inMinSize = cv::Size(0,0),
		cv::Size inMaxSize = cv::Size(0,0),
		bool inXFlip = false)
	{
		mIsOk = false;
		if(readClassifier(inClassifierPath))
		{
			mObjectType = inObjectType;
			mDetectorType = "HaarLikeDetector";
			mScaleFactor = inScaleFactor;
			mMinNeighbors = inMinNeighbors;
			mFlags = inFlags;
			mMinSize = inMinSize;
			mMaxSize = inMaxSize;
			mXFlip = inXFlip;

			mAPrioriConfidence = inAPrioriConfidence;

			mIsOk = true;
		}
		else
			std::cerr<<"Haarlike classifier with path "<<inClassifierPath<<" has failed to open"<<std::endl;
	};
	virtual ~HaarLikeDetector()
	{

	};

	//return number of detected objects, return -1 if error
	virtual int detectObjects(std::vector<cv::Rect>& outDetectedObjects,std::vector<double>& outConfidences, cv::Mat& inFrame);
	bool isOk(){return mIsOk;};

	//***Set/get***//
	//void setHaarCascade(CvHaarClassifierCascade* inClassifier){mClassifier = inClassifier;};
	//CvHaarClassifierCascade* getHaarCascade(){return mClassifier;};

	void setScaleFactor(double inScaleFactor) {mScaleFactor = inScaleFactor;};
	const double getScaleFactor()const{return mScaleFactor;};
	void setMinNeighbors(int inMinNeighbors) {mMinNeighbors = inMinNeighbors;};
	const int getMinNeighbors()const{return mMinNeighbors;};
	void setFlags(int inFlags) {mFlags = inFlags;};
	const int getFlags()const{return mFlags;};
	void setMinSize(cv::Size inMinSize) {mMinSize = inMinSize;};
	const cv::Size getMinSize()const{return mMinSize;};
	void setMaxSize(cv::Size inMaxSize) {mMaxSize = inMaxSize;};
	const cv::Size getMaxSize()const{return mMaxSize;};
	//*** ***//
private:
	bool readClassifier(std::string inPath);
protected:
	//haarlike cascade
	cv::CascadeClassifier		mClassifier;

	//Parameters
	double						mScaleFactor;
	int							mMinNeighbors;
	int							mFlags;
	cv::Size					mMinSize;
	cv::Size					mMaxSize;
	float						mMaxSizeDiff;
	float						mMaxPosDiff;

	bool						mXFlip;		//If this detector is the "other side" of another one.
	bool						mIsOk;
};

#endif
